package com.atguigu.gmall;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author: 李旭
 * @create: 2021-07-12 11:31
 **/
public class CompletableFutureDemo3 {

    //异步编排
    public static void main(String[] args) throws Exception {

    /*    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                5,
                10,
                2,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10)

        );*/
        //并行线程
        CompletableFuture<String> stringCompletableFuture1 = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
                System.out.println("1:" + Thread.currentThread().getName() + "我是第一个任务");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "1";
        });

        CompletableFuture<String> stringCompletableFuture2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("2:" + Thread.currentThread().getName() + "我是第二个任务");
            return "2";
        });

        stringCompletableFuture2.thenApplyAsync(t -> {
            System.out.println("3:" + Thread.currentThread().getName() + "我是第三个任务");
            return "3";
        });


        CompletableFuture.anyOf(stringCompletableFuture1, stringCompletableFuture2).join();
    }
}
